<?php

/**
 * MyProjectNameHere <http://www.example.com>
 * Model Class
 *
 * It is recommended to extend Model classes from WWW_Factory in order to 
 * provide various useful functions and API access for the Model.
 *
 * @package    Factory
 * @author     DeveloperNameHere <email@example.com>
 * @copyright  Copyright (c) 2012, ProjectOwnerNameHere
 * @license    Unrestricted
 * @tutorial   /doc/pages/guide_mvc.htm
 * @since      1.0.0
 * @version    1.0.0
 */

class WWW_model_classified extends WWW_Factory {

	/**
	 * It is recommended to define all data variables here. Usually the 
	 * data variables have the same names as the column names of database 
	 * rows from a table.
	 */	
	public $conn;
	/**
	 * Alternative to __construct()
	 *
	 * WWW_Factory does not allow to overwrite __construct() method, so 
	 * this __initialize() is used instead and loaded automatically when 
	 * object is created.
	 *
	 * @return boolean
	 */
	public function __initialize()
	{
		require('engine/class.www-database.php');
		$this->conn=new WWW_Database();				
		
		require_once('engine/include_dao.php');
		return true;
		
	}
	public function create_category($data)
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->category_name = $data['category_name'];
		$classifiedsCategory->description = $data['description'];
		$classifiedsCategory->created_date = date("Y-m-d H:i:s");
		$classifiedsCategory->updated_date = date("Y-m-d H:i:s");
		$result = DAOFactory::getClassifiedsCategoryDAO()->insert($classifiedsCategory);
		//print_r($result);exit;
	/* $query="insert into `classifieds_category` (category_name,description,created_date,updated_date) VALUES ('".$data['category_name']."','".$data['description']."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."')";
	$result=$this->conn->dbCommand($query);	 */
		//$this->db->last_query();exit;
	if($result !== 0){
			return array('message'=>'Classified Category successfully created');			
		}else{
			return array('message'=>'Classified Category Creation Failed');
		}	
	}
	public function edit_category($data)
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->category_name = $data['category_name'];
		$classifiedsCategory->description = $data['description'];
		$classifiedsCategory->category_id = $data['category_id'];
		$classifiedsCategory->status = $data['status'];
		$classifiedsCategory->updated_date = date("Y-m-d H:i:s");
		$result = DAOFactory::getClassifiedsCategoryDAO()->update($classifiedsCategory);
		//print_r($result);exit;
	/* $query="update `classifieds_category` set category_name='".$data['category_name']."',description='".$data['description']."',updated_date='".date("Y-m-d H:i:s")."' where category_id=".$data['category_id'];
		$result=$this->conn->dbCommand($query); */		
		if($result !== 0){
			return array('message'=>'Updated Successfully');			
		}else{
			return array('message'=>'Updates Failed');
		}	
	
	}
	public function get_category($data)
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->category_id = $data['category_id'];
		$result = DAOFactory::getClassifiedsCategoryDAO()->load($classifiedsCategory);
		//print_r($result);exit;
		/* $query="SELECT * FROM `classifieds_category` WHERE category_id=".$data['category_id'];
		$result=$this->conn->dbMultiple($query);		
		 */
		 if($result !== ''){
			return array('message'=>'Submodule type data','result'=>$result);		
		}else{
			return array('message'=>'submodule by id is failed');
		}	
	
	}
	public function get_category_list($data)
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$result = DAOFactory::getClassifiedsCategoryDAO()->category_list($classifiedsCategory);
		//print_r($result);exit;
		/* $query="SELECT * FROM `classifieds_category` WHERE parent_id='0'";
		$result=$this->conn->dbMultiple($query); */		
		if($result !== ''){
			return array('message'=>'Submodule type data','result'=>$result);		
		}else{
			return array('message'=>'submodule by id is failed');
		}	
	
	}
	public function delete_category($data)
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->category_id = $data['category_id'];
		$classifiedsCategory->status = $data['status'];
		$result = DAOFactory::getClassifiedsCategoryDAO()->delete($classifiedsCategory);
		//print_r($result);exit;
		/* $query="update `classifieds_category` set status='".$data['status']."' where category_id='".$data['category_id']."'";
		$data=$this->conn->dbCommand($query); */
		if($result !== 0)
			return array('message'=>"Classified category status changed Successfully");		
		else
			return array('message'=>'Classified category status changed failed');
	}
	public function all_categories($data)
	{
	$current_page=0;
	$results_per_page=10;
	$order_by="created_date";
	$sort_order="desc";
	if(isset($data['order_by']) && $data['order_by']!='')
	{
		$order_by=$data['order_by'];
	}
	if(isset($data['sort_order']) && $data['sort_order']!='')
	{
		$sort_order=$data['sort_order'];
	}
	if(isset($data['current_page'])&& $data['current_page']!='' || $data['current_page']!=0)
	{
	$current_page=$data['current_page'];
	}
	if(isset($data['results_per_page']) && $data['results_per_page']!='' || $data['results_per_page']!=0){
	$results_per_page=$data['results_per_page'];
	}
	$offset=$current_page;
	/* $query_string = "select * from classifieds_category";
	$query_string1 = "select count(*) as total from classifieds_category"; */
	if (isset($data['search_by']) && $data['search_by']!='')
	{	//print_r($data);exit;
		
		if($data['search_by'] == 'category_name')
		{
			$search_by = "category_name";
			
		}elseif($data['search_by'] == 'description')
		{
			$search_by = "description";
			
		}  
		
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->order_by = $order_by;
		$classifiedsCategory->sort_order = $sort_order;
		$classifiedsCategory->results_per_page = $results_per_page;
		$classifiedsCategory->offset = $offset;
		$classifiedsCategory->search_by = $search_by;
		$classifiedsCategory->search_by_value = $data['search_by_value'];
		$result = DAOFactory::getClassifiedsCategoryDAO()->queryAllSearchBy($classifiedsCategory);
		$totalrows = DAOFactory::getClassifiedsCategoryDAO()->SearchByCount($classifiedsCategory);
		//print_r($result);exit;
		
		/* $query = $query_string." where ".$search_by." like '%".$data['search_by_value']."%' order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
		$query1 = $query_string1." where ".$search_by." like '%".$data['search_by_value']."%'"; */
	}else
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->order_by = $order_by;
		$classifiedsCategory->sort_order = $sort_order;
		$classifiedsCategory->results_per_page = $results_per_page;
		$classifiedsCategory->offset = $offset;
		$result = DAOFactory::getClassifiedsCategoryDAO()->queryAll($classifiedsCategory);
		$totalrows = DAOFactory::getClassifiedsCategoryDAO()->queryAllCount($classifiedsCategory);
		//print_r($totalrows);exit;
		
		/* $query=$query_string." order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
	$query1 = $query_string1; */
	}	
		//$result=$this->conn->dbMultiple($query);
		if($result !== 0){
			//$totalrows = $this->conn->dbSingle($query1);
		return array('message'=>"All Category","info"=>$result,'total'=>$totalrows,'current_page'=>$current_page,'results_per_page'=>$results_per_page);
		}
		else
		return array('message'=>'No Category');
		
	}
	public function create_subcategory($data)
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->category_name = $data['category_name'];
		$classifiedsCategory->description = $data['description'];
		$classifiedsCategory->parent_id = $data['category_id'];
		$classifiedsCategory->created_date = date("Y-m-d H:i:s");
		$classifiedsCategory->updated_date = date("Y-m-d H:i:s");
		$result = DAOFactory::getClassifiedsCategoryDAO()->insertSubcategory($classifiedsCategory);
		//print_r($result);exit;
	/* $query="insert into `classifieds_category` (category_name,parent_id,description,created_date,updated_date) VALUES ('".$data['category_name']."','".$data['category_id']."','".$data['description']."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."')";
	$result=$this->conn->dbCommand($query);	 */
		//$this->db->last_query();exit;
	if($result !== 0){
			return array('message'=>'Subclassified successfully created');			
		}else{
			return array('message'=>'Subclassified Creation Failed');
		}	
	}
	
	public function edit_subcategory($data)
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->category_name = $data['category_name'];
		$classifiedsCategory->description = $data['description'];
		$classifiedsCategory->category_id = $data['category_id'];
		$classifiedsCategory->status = $data['status'];
		$classifiedsCategory->created_date = date("Y-m-d H:i:s");
		$classifiedsCategory->updated_date = date("Y-m-d H:i:s");
		$result = DAOFactory::getClassifiedsCategoryDAO()->updateSubcategory($classifiedsCategory);
		//print_r($result);exit;
		/* $query="update `classifieds_category` set category_name='".$data['category_name']."',description='".$data['description']."',status='".$data['status']."',updated_date='".date("Y-m-d H:i:s")."' where category_id='".$data['category_id']."' and parent_id > 0";
		//print_r($query);exit;
		$result=$this->conn->dbCommand($query);		 */
		if($result !== 0){
			return array('message'=>'Updated Successfully');			
		}else{
			return array('message'=>'Updates Failed');
		}	
	
	}
	
	public function get_subcategory($data)
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->category_id = $data['category_id'];
		$result = DAOFactory::getClassifiedsCategoryDAO()->loadSubcategory($classifiedsCategory);
		//print_r($result);exit;
		//print_r($data);exit;
	/* $query="SELECT * FROM `classifieds_category` where category_id=".$data['category_id']." and parent_id > 0";
		$result=$this->conn->dbMultiple($query); */		
		if($result !== ''){
			return array('message'=>'Submodule type data','result'=>$result);			
		}else{
			return array('message'=>'Submodule by id is failed');
		}	
	
	}
	public function get_subcategory_list($data)
	{	//print_r($data['category_id']);exit;
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->category_id = $data['category_id'];
		$result = DAOFactory::getClassifiedsCategoryDAO()->subcategory_list($classifiedsCategory);
		//print_r($result);exit;
		
		//print_r($data);exit;
	/* $query="SELECT * FROM `classifieds_category` where parent_id ='".$data['category_id']."' and parent_id > 0";
		//print_r($query);exit;
		$result=$this->conn->dbMultiple($query); */		
		if($result !== ''){
			return array('message'=>'Submodule type data','result'=>$result);			
		}else{
			return array('message'=>'Submodule by id is failed');
		}	
	
	}
	
	public function delete_subcategory($data)
	{
		$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->category_id = $data['category_id'];
		$classifiedsCategory->status = $data['status'];
		$result = DAOFactory::getClassifiedsCategoryDAO()->deleteSubcategory($classifiedsCategory);
		//print_r($result);exit;
		
		/* $query="update `classifieds_category` set status='".$data['status']."' where category_id='".$data['category_id']."' and parent_id > 0";
		$data=$this->conn->dbCommand($query); */
		if($result !== 0)
			return array('message'=>"Subcategory Deleted Successfully");		
		else
			return array('message'=>'Subcategory Deletion Fails');
	}
	public function all_subcategories($data)
	{	
	$current_page=0;
	$results_per_page=10;
	$order_by="created_date";
	$sort_order="desc";
	if(isset($data['order_by']) && $data['order_by']!='')
	{
		$order_by=$data['order_by'];
	}
	if(isset($data['sort_order']) && $data['sort_order']!='')
	{
		$sort_order=$data['sort_order'];
	}
	if(isset($data['current_page'])&& $data['current_page']!='' || $data['current_page']!=0)
	{
	$current_page=$data['current_page'];
	}
	if(isset($data['results_per_page']) && $data['results_per_page']!='' || $data['results_per_page']!=0){
	$results_per_page=$data['results_per_page'];
	}
	$offset=$current_page;
	/* $query_string = "select * from classifieds_category";
	$query_string1 = "SELECT count(*) as total from classifieds_category"; */
	if (isset($data['search_by']) && $data['search_by']!='')
	{	//print_r($data);exit;
		
		if($data['search_by'] == 'category_name')
		{
			$search_by = "category_name";
			
		}elseif($data['search_by'] == 'description')
		{
			$search_by = "description";
			
		} 

			$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->order_by = $order_by;
		$classifiedsCategory->sort_order = $sort_order;
		$classifiedsCategory->results_per_page = $results_per_page;
		$classifiedsCategory->offset = $offset;
		$classifiedsCategory->search_by = $search_by;
		$classifiedsCategory->search_by_value = $data['search_by_value'];
		$result = DAOFactory::getClassifiedsCategoryDAO()->subcategorySearchBy($classifiedsCategory);
		$totalrows = DAOFactory::getClassifiedsCategoryDAO()->subcategoryCount($classifiedsCategory);
		print_r($result);exit;
		/* $query = $query_string." where ".$search_by." like '%".$data['search_by_value']."%' and parent_id > '0' order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
		$query1 = $query_string1." where ".$search_by." like '%".$data['search_by_value']."%' and parent_id > '0'"; */
	}else
	{
			$classifiedsCategory = new ClassifiedsCategory();
		$classifiedsCategory->order_by = $order_by;
		$classifiedsCategory->sort_order = $sort_order;
		$classifiedsCategory->results_per_page = $results_per_page;
		$classifiedsCategory->offset = $offset;
		$result = DAOFactory::getClassifiedsCategoryDAO()->queryAllSubcategory($classifiedsCategory);
		$totalrows = DAOFactory::getClassifiedsCategoryDAO()->queryAllSubcategoryCount($classifiedsCategory);
		//print_r($result);exit;
	/* $query = $query_string." where parent_id > '0' order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
	$query1 = $query_string1." where parent_id > '0'"; */
	}	
		//print_r($query);exit;
		//$result=$this->conn->dbMultiple($query);
		if($result !== ''){
			//$totalrows = $this->conn->dbSingle($query1);
		return array('message'=>"All ","info"=>$result,'total'=>$totalrows,'current_page'=>$current_page,'results_per_page'=>$results_per_page);
		}
		else
		return array('message'=>'No Subcategory');
	}
	public function create_classified_question($data)
	{
		$classifiedQuestion = new ClassifiedQuestion();
		$classifiedQuestion->question = $data['question'];
		$classifiedQuestion->user_email = $data['user_email'];
		$classifiedQuestion->classified_id = $data['classified_id'];
		$classifiedQuestion->admin_id = $data['admin_id'];
		$classifiedQuestion->replay = $data['replay'];
		$classifiedQuestion->is_public = $data['is_public'];
		$classifiedQuestion->created_date = date("Y-m-d H:i:s");
		$classifiedQuestion->updated_date = date("Y-m-d H:i:s");
		$result = DAOFactory::getClassifiedQuestionsDAO()->insert($classifiedQuestion);
		//print_r($result);exit;
		
	/*  $query="insert into `classified_questions` (question,user_email,classified_id,admin_id,replay,is_public,created_date,updated_date) VALUES ('".$data['question']."','".$data['email']."','".$data['classified_id']."','".$data['admin_id']."','".$data['replay']."','".$data['is_public']."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."')";
	//print_r($query);exit;
	$result=$this->conn->dbCommand($query);  */
		//$this->db->last_query();exit;
	if($result !== 0){
			return array('message'=>'Subclassified successfully created');			
		}else{
			return array('message'=>'Subclassified Creation Failed');
		}	
	}
	public function edit_classified_question($data)
	{
		$classifiedQuestion = new ClassifiedQuestion();
		$classifiedQuestion->question_id = $data['question_id'];
		$classifiedQuestion->question = $data['question'];
		$classifiedQuestion->question = $data['question'];
		$classifiedQuestion->user_email = $data['user_email'];
		$classifiedQuestion->classified_id = $data['classified_id'];
		$classifiedQuestion->admin_id = $data['admin_id'];
		$classifiedQuestion->replay = $data['replay'];
		$classifiedQuestion->is_public = $data['is_public'];
		$classifiedQuestion->status = $data['status'];
		$classifiedQuestion->updated_date = date("Y-m-d H:i:s");
		$result = DAOFactory::getClassifiedQuestionsDAO()->update($classifiedQuestion);
		//print_r($result);exit;
		
		/* $query="update `classified_questions` set question='".$data['question']."',user_email='".$data['email']."',classified_id='".$data['classified_id']."',admin_id='".$data['admin_id']."',replay='".$data['replay']."',is_public='".$data['is_public']."',status='".$data['status']."',updated_date='".date("Y-m-d H:i:s")."' where question_id=".$data['question_id'];
		//print_r($query);exit;
		$result=$this->conn->dbCommand($query); */		
		if($result !== 0){
			return array('message'=>'Updated Successfully');			
		}else{
			return array('message'=>'Updates Failed');
		}	
	
	}
	public function get_classified_question($data)
	{
		$classifiedQuestion = new ClassifiedQuestion();
		$classifiedQuestion->question_id = $data['question_id'];
		$result = DAOFactory::getClassifiedQuestionsDAO()->load($classifiedQuestion);
		//print_r($result);exit;
		//print_r($data);exit;
	/* $query="SELECT * FROM `classified_questions` where question_id=".$data['question_id'];
		$result=$this->conn->dbMultiple($query);	 */	
		if($result !== ''){
			return array('message'=>'Submodule type data','result'=>$result);			
		}else{
			return array('message'=>'Submodule by id is failed');
		}	
	
	}
	public function delete_classified_question($data)
	{
		$classifiedQuestion = new ClassifiedQuestion();
		$classifiedQuestion->question_id = $data['question_id'];
		$classifiedQuestion->status = $data['status'];
		$result = DAOFactory::getClassifiedQuestionsDAO()->delete($classifiedQuestion);
		//print_r($result);exit;
		
		/* $query="update `classified_questions` set status='".$data['status']."' where question_id='".$data['question_id']."'";
		$data=$this->conn->dbCommand($query); */
		if($result !== 0)
			return array('message'=>"Question Deleted Successfully");		
		else
			return array('message'=>'Question Deletion Fails');
	}
	public function all_classified_question($data)
	{	
	$current_page=0;
	$results_per_page=10;
	$order_by="created_date";
	$sort_order="desc";
	if(isset($data['order_by']) && $data['order_by']!='')
	{
		$order_by=$data['order_by'];
	}
	if(isset($data['sort_order']) && $data['sort_order']!='')
	{
		$sort_order=$data['sort_order'];
	}
	if(isset($data['current_page'])&& $data['current_page']!='' || $data['current_page']!=0)
	{
	$current_page=$data['current_page'];
	}
	if(isset($data['results_per_page']) && $data['results_per_page']!='' || $data['results_per_page']!=0){
	$results_per_page=$data['results_per_page'];
	}
	$offset=$current_page;
	/* $query_string = "select * from classified_questions";
	$query_string1 = "SELECT count(*) as total from classified_questions"; */
	if (isset($data['search_by']) && $data['search_by']!='')
	{	//print_r($data);exit;
		
		if($data['search_by'] == 'question')
		{
			$search_by = "question";
			
		}  
		$classifiedQuestion = new ClassifiedQuestion();
		$classifiedQuestion->order_by = $order_by;
		$classifiedQuestion->sort_order = $sort_order;
		$classifiedQuestion->results_per_page = $results_per_page;
		$classifiedQuestion->offset = $offset;
		$classifiedQuestion->search_by = $search_by;
		$classifiedQuestion->search_by_value = $data['search_by_value'];
		$result = DAOFactory::getClassifiedQuestionsDAO()->queryAllSearchBy($classifiedQuestion);
		$totalrows = DAOFactory::getClassifiedQuestionsDAO()->SearchByCount($classifiedQuestion);
		//print_r($totalrows);exit;
		
		/* $query = $query_string." where ".$search_by." like '%".$data['search_by_value']."%' order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
		$query1 = $query_string1." where ".$search_by." like '%".$data['search_by_value']."%'"; */
	}else
	{
		$classifiedQuestion = new ClassifiedQuestion();
		$classifiedQuestion->order_by = $order_by;
		$classifiedQuestion->sort_order = $sort_order;
		$classifiedQuestion->results_per_page = $results_per_page;
		$classifiedQuestion->offset = $offset;
		$result = DAOFactory::getClassifiedQuestionsDAO()->queryAll($classifiedQuestion);
		$totalrows = DAOFactory::getClassifiedQuestionsDAO()->queryAllCount($classifiedQuestion);
		//print_r($result);exit;
	/* $query = $query_string." order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
	$query1 = $query_string1; */
	}	
		//print_r($query);exit;
		//$result=$this->conn->dbMultiple($query);
		if($result !== ''){
			//$totalrows = $this->conn->dbSingle($query1);
		return array('message'=>"All ","info"=>$result,'total'=>$totalrows['total'],'current_page'=>$current_page,'results_per_page'=>$results_per_page);
		}
		else
		return array('message'=>'No Questions');
	}
	public function create_classified($data)
	{
	if($data['classified_type']=="premium")
	{
		
		$expire_on = 30;
		
	}else if($data['classified_type']=="standard")
	{
		$expire_on = 15;
	}	
			$file = $data['classified_image']['tmp_name'];
			$filename = time().$data["classified_image"]['name'];
			$classified_image_path="uploads/classifieds/".$filename;
			move_uploaded_file($file, $classified_image_path);
		
		$query="insert into `classifieds` (category_id,subcategory_id,start_date,description,contact_details,phone_number,mobile_number,email,user_name,classified_type,show_my_contact,expire_in,classified_image,classified_url,meta_description,meta_keywords,created_date,updated_date) VALUES ('".$data['category_id']."','".$data['subcategory_id']."','".$data['start_date']."','".$data['description']."','".$data['contact_details']."','".$data['phone_number']."','".$data['mobile_number']."','".$data['email']."','".$data['name']."','".$data['classified_type']."','".$data['shou_my_contact']."','".$expire_on."','".$this->conn->baseurl().$classified_image_path."','".$data['classified_url']."','".$data['meta_description']."','".$data['meta_keywords']."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."')";
	//print_r($query);exit;
	$result=$this->conn->dbCommand($query);	
		if($result){
			return array('message'=>'Classified successfully created');			
		}else{
			return array('message'=>'Classified Creation Failed');
		}	
	}
	public function edit_classified($data)
	{
	if($data['classified_type']=="premium")
	{
		
		$expire_on = 30;
		
	}else if($data['classified_type']=="standard")
	{
		$expire_on = 15;
	}	
			if($data['classified_image']!="")
			{
			$file = $data['classified_image']['tmp_name'];
			$filename = time().$data["classified_image"]['name'];
			$classified_image_path="uploads/classifieds/".$filename;
			move_uploaded_file($file, $classified_image_path);
			}
			else
			{
				$classified_image_path = "";
			}
	$query="update `classifieds` set  category_id='".$data['category_id']."',subcategory_id='".$data['subcategory_id']."',start_date='".$data['start_date']."',description='".$data['description']."',contact_details='".$data['contact_details']."',phone_number='".$data['phone_number']."',mobile_number='".$data['mobile_number']."',email='".$data['email']."',user_name='".$data['name']."',classified_type='".$data['classified_type']."',show_my_contact='".$data['show_my_contact']."',expire_in='".$expire_on."'".($classified_image_path!="" ? ',banner_image='.$this->conn->baseurl().$classified_image_path : '').",classified_url='".$data['classified_url']."',meta_description='".$data['meta_description']."',meta_keywords='".$data['meta_keywords']."',status='".$data['status']."',updated_date='".date("Y-m-d H:i:s")."' where classified_id='".$data['classified_id']."' ";
	
	//print_r($query);exit;
	$result=$this->conn->dbCommand($query);	
		if($result){
			return array('message'=>'Classified successfully created');			
		}else{
			return array('message'=>'Classified Creation Failed');
		}	
	}
	public function get_classified($data)
	{
	
	$query="select c.*,ct.category_id,ct.category_name,cct.category_id as subcategory_id,cct.category_name as subcategory_name from `classifieds` c left join classifieds_category ct on ct.category_id=c.category_id left join classifieds_category cct on cct.category_id=c.subcategory_id where classified_id='".$data['classified_id']."' and TIMESTAMPDIFF(DAY, start_date, '".date("Y-m-d H:i:s")."') < expire_in";
	
	//print_r($query);exit;
	$result=$this->conn->dbMultiple($query);	
		if($result){
			return array('message'=>'Classified successfully created', 'result'=>$result);			
		}else{
			return array('message'=>'Classified Creation Failed');
		}	
	}
	public function delete_classified($data)
	{
	
	$query="update `classifieds` set status='".$data['status']."' where classified_id='".$data['classified_id']."'";
	
	//print_r($query);exit;
	$result=$this->conn->dbCommand($query);	
		if($result){
			return array('message'=>'Classified deleted successfully');			
		}else{
			return array('message'=>'Classified deleted Failed');
		}	
	}
	public function all_classified($data)
	{	
	$current_page=0;
	$results_per_page=10;
	$order_by="created_date";
	$sort_order="desc";
	if(isset($data['order_by']) && $data['order_by']!='')
	{
		$order_by=$data['order_by'];
	}
	if(isset($data['sort_order']) && $data['sort_order']!='')
	{
		$sort_order=$data['sort_order'];
	}
	if(isset($data['current_page'])&& $data['current_page']!='' || $data['current_page']!=0)
	{
	$current_page=$data['current_page'];
	}
	if(isset($data['results_per_page']) && $data['results_per_page']!='' || $data['results_per_page']!=0){
	$results_per_page=$data['results_per_page'];
	}
	$offset=$current_page;
	$query_string = "select c.*,ct.category_id,ct.category_name,cct.category_id as subcategory_id,cct.category_name as subcategory_name from `classifieds` c left join classifieds_category ct on ct.category_id=c.category_id left join classifieds_category cct on cct.category_id=c.subcategory_id";
	$query_string1 = "SELECT count(*) as total from `classifieds` c left join classifieds_category ct on ct.category_id=c.category_id left join classifieds_category cct on cct.category_id=c.subcategory_id";
	if (isset($data['search_by']) && $data['search_by']!='')
	{	//print_r($data);exit;
		
		if($data['search_by'] == 'category_name')
		{
			$search_by = "ct.category_name";
			
		}elseif($data['search_by'] == 'start_date')
		{
			$search_by = "start_date";
			
		}
		if($data['search_by'] == 'email')
		{
			$search_by = "email";
			
		}elseif($data['search_by'] == 'description')
		{
			$search_by = "c.description";
			
		}
		if($data['search_by'] == 'user_name')
		{
			$search_by = "user_name";
			
		}
		$query = $query_string." where ".$search_by." like '%".$data['search_by_value']."%' order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
		$query1 = $query_string1." where ".$search_by." like '%".$data['search_by_value']."%'";
	}else
	{
	$query = $query_string." order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
	$query1 = $query_string1;
	}	
		//print_r($query);exit;
		$result=$this->conn->dbMultiple($query);
		if($result){
			$totalrows = $this->conn->dbSingle($query1);
		return array('message'=>"All ","info"=>$result,'total'=>$totalrows['total'],'current_page'=>$current_page,'results_per_page'=>$results_per_page);
		}
		else
		return array('message'=>'No Classifieds');
	}
	
}

	
?>